home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 1 / Gold Medal Software Volume 1 (Gold Medal) (1994).iso / prog / dasv10_.arj / PASSWORD.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-10  |  1.3 KB  |  66 lines

  1. #include <dos.h>
  2. #include <iostream.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6.  
  7. //Program concieved by David A. Scouten 04/02/93
  8. //completed and revised 07/26/93
  9.  
  10. char code[9], password[9];
  11. int count=0;
  12. FILE *infptr, *outfptr;
  13.  
  14. void main()
  15. {//begin main
  16.     if ((infptr=fopen("password.dat","r"))==NULL) {//check for data file
  17.         cout<<"\nCannot open 'password.dat' file.";
  18.         goto WRITE_DATA;
  19.         }
  20.         while (!feof(infptr)) {//read data from file
  21.         fscanf(infptr,"%s", &code);
  22.         }//end while
  23. fclose(infptr);
  24. goto START;
  25.  
  26. WRITE_DATA: //write new password
  27. if ((outfptr=fopen("password.dat","w"))==NULL) {//check for data file
  28.         cout<<"\nCannot open 'password.dat' file";
  29.         }
  30.         cout<<"\nEnter NEW Password: ";
  31.         cin>>code;
  32.         fprintf(outfptr, "%s", code);//write data to file
  33.         fclose(outfptr);
  34.  
  35. START:
  36. //set tries counter
  37. count=3;
  38. while (count!=0){
  39.  
  40. //display user prompt
  41. cout<<"\nTries Left: "<<count;
  42. cout<<"\nEnter CURRENT Password: ";
  43. //get keyboard input
  44. cin>>password;
  45.  
  46. //password correctly entered
  47. if (strcmp(password,code)==0){
  48.     cout<<"\nAccess Granted.\n";
  49.     exit(0);
  50.     }
  51. else
  52.     {//password incorrectly entered
  53.     cout<<"Incorrect Password!\n";
  54.     count--;
  55.     }//end if
  56.  
  57. }//end while
  58.  
  59. //system lockup
  60. cout<<"*Access Denied*";
  61. cout<<"\n*SYSTEM LOCKED*";
  62. LOCKUP:
  63. delay(100);
  64. goto LOCKUP;
  65.  
  66. }//end main